package com.yeyks.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;
import com.yeyks.common.param.member.MemberCardSellRelationDownQueryParam;
import com.yeyks.common.param.member.MemberCardSellRelationQueryParam;
import com.yeyks.common.utils.DateUtils;
import com.yeyks.common.utils.ObjectConvertUtil;
import com.yeyks.vip.dal.domain.MemberCardSellRelation;
import com.yeyks.vip.dal.dao.MemberCardSellRelationMapper;
import com.yeyks.vip.service.MemberCardSellRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 销售关系记录 服务实现类
 * </p>
 *
 * @author yun
 * @since 2019-10-10
 */
@Service
public class MemberCardSellRelationServiceImpl extends ServiceImpl<MemberCardSellRelationMapper, MemberCardSellRelation> implements MemberCardSellRelationService {

    @Override
    public List<MemberCardSellRelation> queryByParam(MemberCardSellRelationQueryParam param) {

        Map<String, Object> paramMap = this.convertQueryMap(param);

        PageHelper.startPage(param.getPageNum(), param.getPageSize());

        return this.baseMapper.queryByParam(paramMap);
    }

    @Override
    public int queryCount(MemberCardSellRelationQueryParam param) {

        Map<String, Object> paramMap = this.convertQueryMap(param);

        return this.baseMapper.queryCount(paramMap);
    }

    @Override
    public List<MemberCardSellRelation> queryDownLoad(MemberCardSellRelationDownQueryParam param) {


        return this.baseMapper.queryByDownLoadParam(param);
    }

    /**
     * 转换查询条件
     * @param param
     * @return
     */
    private Map<String, Object> convertQueryMap(MemberCardSellRelationQueryParam param){

        Map<String, Object> map = ObjectConvertUtil.objectToMap(param);
        assert map != null;
        map.put("orderNo", param.getOrderNo());
        Date startDate = DateUtils.yyyyMMddToDate(param.getCreateTime());
        map.put("startTime", startDate);
        if (null != startDate) {
            Date endDate = DateUtils.afterDaysToDate(startDate, 1L);
            map.put("endTime", endDate);
        }
        return map;
    }
}
